#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
websocket 链接管理
"""

from typing import List, Dict

from starlette.websockets import WebSocket


class ConnectionManager:

    def __init__(self):
        """存放链接"""
        self.active_connections: List[Dict[str, WebSocket]] = []

    async def connect(self, user: str, ws: WebSocket):
        """链接"""
        self.active_connections.append({"user": user, "ws": ws})

    async def disconnect(self, user: str, ws: WebSocket):
        """断开链接，移除"""
        self.active_connections.remove({"user": user, "ws": ws})



